package com.church.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.church.dao.AnnouncementDao;
import com.church.db.Announcement;

public class AnnouncementDaoImpl extends HibernateDaoSupport implements AnnouncementDao {

	@Override
	public String add(Announcement announcement) {
		this.getHibernateTemplate().save(announcement);
		return "success";
	}

	@Override
	public String update(Announcement announcement) {
		this.getHibernateTemplate().update(announcement);
		return "success";
	}

	@Override
	public String remove(Announcement announcement) {
		this.getHibernateTemplate().delete(announcement);
		return "success";
	}

	@Override
	public List<Announcement> getAnnouncementByGroup(String group) {
		
		return this.getHibernateTemplate().find("from Announcement where state='0' and group='"+group+"'");
	}

	@Override
	public Announcement getAnnouncementById(long id) {
		List<Announcement> list=this.getHibernateTemplate().find("from Announcement where id="+id);
		if(list.size()>0)
		{
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Announcement> getList() {
		return this.getHibernateTemplate().find("from Announcement where state!='3'");
	}

}
